import { FindOption, X } from 'x-orm';
import { CaipiaoOrder, OrderStatus } from './../ml/caipiao_order';
import { failed, success } from './../../../lib/utils';
import { caipiao } from './../../../collect';
import { Member } from './../ml/member';
import { V, Connection } from 'x-engine';


@V.Controller({
    type : Connection.HTTP,
    dataType : "json",
    url : "/api/order/:method",
    authorization : ['member']
})
export class OrderController{

    /**
     * 增加订单
     * @param member 
     * @param goods 
     * @param num 
     * @param guess 
     */
    async add(
        member : Member,
        goods : '50' | '100',
        num : number,
        guess : 'single' | 'double'
    ){
        if(goods != '50' && goods != '100'){
            return failed();
        }
        // if(goods)
    }


    /**
     * 取消订单
     */
    async cancel(
        member : Member,
        order_id : number
    ){
        if(!order_id){
            return failed();
        }
        const oinfo = await X.of(CaipiaoOrder).findOne(order_id);
        if(!oinfo){
            return failed();
        }

        if(oinfo.status != OrderStatus.notpay){
            return failed();
        }

        oinfo.status = OrderStatus.canceled;
        await X.of(CaipiaoOrder).save(oinfo);
        return success();
    }

    /**
     * 领奖
     */



    /**
     * 转卖
     */
    


}